//有子项的菜单 //存在3个部分： title/右侧>图标/子菜单
<template>
  <div class="sub-menu" @mouseenter="showSubMenu" @mouseleave="hideSubMenu">
    <div class="title">
      <!-- 标题 -->
      <slot name="title"></slot>
      <!-- 小箭头 -->
      <span class="icon">&gt;</span>
    </div>
    <!-- 子项菜单 -->
    <div class="sub-item" v-show="subMenuShow">
      <!-- 用户自己填写的slot -->
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "SubMenu",
  data() {
    return {
      subMenuShow: false,
    };
  },
  methods: {
    showSubMenu() {
      this.subMenuShow = true;
    },
    hideSubMenu() {
      this.subMenuShow = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.sub-menu {
  position: relative;
  height: 50px;

  .title {
    position: relative;
    height: 50px;
    line-height: 50px;
    text-align: center;

    .icon {
      position: absolute;
      top: 0;
      right: 15px;
    }
  }

  .sub-item {
    position: absolute;
    left: 100%;
    top: 0;
    width: 100%;
    background-color: #333;
  }
}
</style>
